package com.finger.crowd.controller;

import com.finger.crowd.api.MySQLRemoteService;
import com.finger.crowd.constant.CrowdConstant;
import com.finger.crowd.entity.vo.PortalTypeVO;
import com.finger.crowd.util.ResultEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class PortalController {

    private Logger logger = LoggerFactory.getLogger(PortalController.class);

    @Autowired
    private MySQLRemoteService mySQLRemoteService;

    @RequestMapping("/")
    public String protal(
            ModelMap modelMap
    ) {

        ResultEntity<List<PortalTypeVO>> portalTypeVOListResult = mySQLRemoteService.getAllPortalProject();

        logger.info(portalTypeVOListResult.toString());

        if (ResultEntity.getSUCCESS().equals(portalTypeVOListResult.getResult())) {

            List<PortalTypeVO> portalTypeVOList = portalTypeVOListResult.getData();

            modelMap.addAttribute(CrowdConstant.ATTR_NAME_PORTALVO, portalTypeVOList);

        }
        return "portal";
    }
}
